package com.cloudspace.jindun.activity.dianhua;

import android.content.Context;
import android.os.Bundle;
import android.text.InputType;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import com.cloudspace.jindun.R;
import com.cloudspace.jindun.activity.CustomTitleBaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by plato on 2016/12/24.
 */

public class DialingActivity extends CustomTitleBaseActivity {
    @Bind(R.id.phone_listview_contracts)
    public ListView listView;
    @Bind(R.id.phone_edittext_call)
    public EditText mPhoneEditTextCall;
    public List<Person> persons;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_dialing,false);
        ButterKnife.bind(this);

        persons=new ContractsAct().initData();
        listView.setAdapter(new MyAdapter(this,persons));
    }

    public class MyAdapter extends BaseAdapter {
        private List<Person> list;
        private LayoutInflater inflater;

        public MyAdapter(Context context, List<Person> list) {
            inflater = LayoutInflater.from(context);
            this.list = list;
        }

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int position) {
            return list.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            MyAdapter.ViewHolder holder;
            if (convertView == null) {
                holder = new MyAdapter.ViewHolder();
                convertView = inflater.inflate(R.layout.item_dialing_people, null);
                holder.tv_company = (TextView) convertView.findViewById(R.id.phone_textview_company);
                holder.tv_name = (TextView) convertView.findViewById(R.id.phone_textview_name);
                holder.tv_number= (TextView) convertView.findViewById(R.id.phone_textview_number);
                convertView.setTag(holder);
            } else {
                holder = (MyAdapter.ViewHolder) convertView.getTag();
            }
            holder.tv_company.setText(list.get(position).getCompany());
            holder.tv_name.setText(list.get(position).getName());
            holder.tv_number.setText(list.get(position).getPhonenumber());
            return convertView;
        }

        private class ViewHolder {
            private TextView tv_company;
            private TextView tv_name;
            private TextView tv_number;
        }
    }
    private class Person {
        private String name;
        private String phonenumber;
        private String company;

        public Person(String company, String name, String phonenumber) {
            this.company = company;
            this.name = name;
            this.phonenumber = phonenumber;
        }

        public String getCompany() {
            return company;
        }

        public String getName() {
            return name;
        }

        public String getPhonenumber() {
            return phonenumber;
        }
    }

    public class ContractsAct {

        public List<Person> initData(){
            List<Person> persons=new ArrayList<>();
            persons=new ArrayList<>();
            persons.add(new Person("总务处","赵平","123456"));
            persons.add(new Person("总务处","赵平","123456"));
            persons.add(new Person("总务处","赵平","123456"));
            persons.add(new Person("总务处","赵平","123456"));
            persons.add(new Person("总务处","赵平","123456"));
            persons.add(new Person("总务处","赵平","123456"));
            persons.add(new Person("总务处","赵平","123456"));
            return persons;
        }

    }
}
